﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Max.DAL
{
    public class UserModel
    {
        private MAXDBEntities maxDBEntity = new MAXDBEntities();

        public User GetUserByEmail(string email)
        {
            return  (from n in maxDBEntity.Users
                    where n.user_email.Equals(email.Trim())
                    select n).SingleOrDefault();

        }

        public User GetUserByUserID(int userId)
        {
            return (from n in maxDBEntity.Users
                    where n.user_id.Equals(userId)
                    select n).SingleOrDefault();

        }

        public List<User> GetAllUsers()
        {
            return (from n in maxDBEntity.Users
                   
                    select n).ToList<User>();
        }

        public bool AddUser(User userData)
        {
            maxDBEntity.Users.Add(userData);
            maxDBEntity.SaveChanges();
            return true;
        
        }

        public bool UpateUserByUserID(User userData)
        {
            
            var user = this.GetUserByUserID(userData.user_id);

            user.user_id = userData.user_id;
            user.user_email = userData.user_email;
            user.user_name = userData.user_name;
            user.user_password = userData.user_password;
            user.user_modify_date = userData.user_modify_date;

            maxDBEntity.Users.Add(user);                
            maxDBEntity.SaveChanges();
            
            return true;
        
        }

    }
}
